$(document).ready(function () {
    query2();
});




//自修申请
var query2 = function () {
    $('#dataTable2').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.list",
        "sAjaxSource": "http://localhost:8080/selfStudy/queryAll",
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>",
            "sZeroRecords": "暂无相关信息",
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",

        "aoColumns": [
            {"mDataProp": "studybyoneselfId"},
            {"mDataProp": "stuInfoId"},
            {"mDataProp": "courseId"},
            {"mDataProp": "courseName"},
            {"mDataProp": "studybyoneselfFlag",
                "mRender": function(data) {
                    var value = "";
                    if (data==0){
                        value = "<span  class='label label-danger mr10 mb10' id='agree'>已拒绝</span>";
                    }
                    if (data==1){
                        value = "<span  class='label label-success mr10 mb10' id='agree'>已同意</span>";
                    }
                    if (data==2){
                        value = "<a href='#'><span  class='label label-primary mr10 mb10' id='agree'>同意</span></a>"+
                        "<a href='#'><span  class='label label-yellow mr10 mb10' id='refuse'>拒绝</span></a>";
                    }
                    return value;
                }
            }

        ],
    })
};



$(document).on('click', '#agree', function () {


    var studybyoneselfId = $(this).parents("tr").children(0).eq(0).text();


    $.ajax({
        url: "http://localhost:8080/selfStudy/update?studybyoneselfFlag="+1+"&studybyoneselfId="+studybyoneselfId,
        type: "GET",
        dataType: "json",
        success:function (data) {
            console.log(data)
            var msg="操作成功";
            if (data.code==0){
                $.each(data.data,function (key,value) {
                    if(key=="0606"){
                        msg=value;
                        layer.msg(msg);
                        setTimeout('delayer()',3000)
                        location.reload();
                    }
                });
            } else {
                layer.msg(msg);
                location.reload();
            }


        },
        error:function () {
            layer.alert("你的网络太慢了！添加失败!再试一次吧！");
        }
    });


});



$(document).on('click', '#refuse', function () {


    var studybyoneselfId = $(this).parents("tr").children(0).eq(0).text();


    $.ajax({
        url: "http://localhost:8080/selfStudy/update?studybyoneselfFlag="+0+"&studybyoneselfId="+studybyoneselfId,
        type: "GET",
        dataType: "json",
        success:function (data) {
            console.log(data)
            var msg="操作成功";
            if (data.code==0){
                $.each(data.data,function (key,value) {
                    if(key=="0606"){
                        msg=value;
                        layer.msg(msg);
                        setTimeout('delayer()',3000)
                        location.reload();
                    }
                });
            } else {
                layer.msg(msg);
                location.reload();
            }


        },
        error:function () {
            layer.alert("你的网络太慢了！添加失败!再试一次吧！");
        }
    });


});


